app.controller('GetTopdataCtrl',function ($scope,$http,$localStorage,$location,$window,$state) {
	$scope.namedata = $localStorage.cur_user.uname;
	$scope.mmData = $localStorage.layers_info;	
	var layerdata = $state.params.layerdata.split(',');	
	var school_name,school_id,building_type,campus_building_id,building_name,layer_id,layer_name;
	$scope.layerdata = [];
	if(layerdata!=null&&layerdata!=undefined&&layerdata!=''){	
		if(layerdata[0]!='所有学校'){
			if(layerdata[1]!=''){
				if(layerdata[2]!=''){
					if(layerdata[3]!=''){
						school_name = layerdata[0];
						school_id = layerdata[1].split('+')[1];
						building_type = layerdata[1].split('+')[0];
						campus_building_id = layerdata[3].split('+')[1];
						building_name = layerdata[2];
						layer_id = layerdata[3].split('+')[2];
						layer_name = layerdata[3].split('+')[0];
						$scope.layerdata.push(school_name);
				    	$scope.layerdata.push(building_type);
				    	$scope.layerdata.push(building_name);
				    	$scope.layerdata.push(layer_name);
					}else{
						school_name = layerdata[0];
						school_id = layerdata[1].split('+')[1];
						building_type = layerdata[1].split('+')[0];
						campus_building_id = $scope.mmData[layerdata[0]][layerdata[1].split('+')[0]][layerdata[2]].campus_id;
						building_name = layerdata[2];
						layer_id = '';
						layer_name = '所有层';
						$scope.layerdata.push(school_name);
				    	$scope.layerdata.push(building_type);
				    	$scope.layerdata.push(building_name);
				    	$scope.layerdata.push(layer_name);

					}

				}else{
					school_name = layerdata[0];
					school_id = layerdata[1].split('+')[1];
					building_type = layerdata[1].split('+')[0];
					campus_building_id = '';
					building_name = '所有楼';
					layer_id = '';
					layer_name = '';
					$scope.layerdata.push(school_name);
				    $scope.layerdata.push(building_type);
				    $scope.layerdata.push(building_name);
				}

			}else{
				school_name = layerdata[0];
				school_id = $scope.mmData[layerdata[0]].school_id;
				building_type = '所有类型';	
				campus_building_id = '';
				building_name = '';
				layer_id = '';
				layer_name = '';
				$scope.layerdata.push(school_name);
				$scope.layerdata.push(building_type);
			}

		}else{
			school_name = '所有学校';	
			school_id = ''	;
			building_type = '';	
			campus_building_id = '';
			building_name = '';
			layer_id = '';
			layer_name = '';
			$scope.layerdata.push(school_name);


		}
	}


	var keydata = $state.params.key;
	var keys = {};
	$scope.keys = {};
	if(keydata!=''){
		if(keydata=="power"){
			keys.power = "实时功率"
		}
		if(keydata=="current"){
			keys.current = "实时电流"		
		}
		if(keydata=="voltage"){
			keys.voltage = "实时电压"
		}
		if(keydata=="total_power"){
			keys.total_power = "总电量"
		}
		$scope.keys = keys;
	}else{
		$scope.keys.param = "参数没有选择"
	}

	// $scope.currentPage = 1;//初始当前页
 //    $scope.maxSize = 3;//最多显示3页其他的用···代替
    $http.post(
        $scope.app.backendurl+"tbl-electricity/top",
        {    
            // 'page':$scope.currentPage,            
            'school_name':school_name,
            'school_id':school_id,
            'key':$state.params.key,	               	
            'campus_building_id':campus_building_id,
            'building_name':building_name,
            'building_type':building_type,
            'layer_id':layer_id,
            'layer_name':layer_name,
            'top': 20,
            'token':$localStorage.token                  

        }
      ).success(function (data) {
         //console.log(data);
        if(data.code==0&&data.msg=="读取成功"){             
          $scope.aaData = data.data.models;
          // $scope.totalItems = data.data.page.totalCount;          
        }
        if(data.code==20001&&data.msg=='请先登录'){
          $location.path('access.signin');
        }
        if(data.code==1){
        	alert(data.msg)
        }  

   
    }).error(function(data){
      console.log(data);
    })
	


	

})